package mest.controller.hws;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import mest.service.hws.plan_productjob_workfinish_recordService;
import mest.service.system.DBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/plan_productjob_workfinish_recordController")
@CrossOrigin
public class plan_productjob_workfinish_recordController {

    @Resource
    private plan_productjob_workfinish_recordService ppwr;

    @Autowired
    private DBService dbService;

        //新增
        @RequestMapping("/insert")
        public String insert(@RequestBody JSONArray json){
            System.out.println("进入方法");
            List<Map<String,Object>> record = json.toJavaObject(List.class);
            for (Map<String,Object> map:record){
                map.put("ppwId",map.get("id"));
                map.put("theirDb",dbService.getDbName());
            }
            System.out.println(record);
            return  ppwr.insertModel(record);
        }
    
        /*//更新
        @RequestMapping("/updateByone")
        public String updateByPrimaryKey(@RequestBody JSONObject json) {
            System.out.println("进入更新方法");
            Map<String,Object> record = json.toJavaObject(Map.class);
            return  ppwr.updateByPrimaryKey(record);
        }
    
        //根据id查询
        @RequestMapping("/selectById")
        public String selectByPrimaryKey(@RequestBody JSONObject json) {
            System.out.println("根据id查询");
            Map<String,Object> record = json.toJavaObject(Map.class);
            return ppwr.selectByPrimaryKey(record);
        }*/
    
        //查询所有
        @RequestMapping("/selectAll")
        public Map<String,Object> selectPrimary(@RequestBody JSONObject json) {
            System.out.println("查询全部");
            Map<String,Object> record = json.toJavaObject(Map.class);
            record.put("theirDb",dbService.getDbName());
            return  ppwr.selectAll(record);
        }

}
